package mylib.dir;

import java.io.PrintWriter;
import java.util.Locale;

/**
 * Created with IntelliJ IDEA.
 * User: 1
 * Date: 17.07.12
 * Time: 23:30
 * To change this template use File | Settings | File Templates.
 */
public class OutputUtils {
    public static void outArray(PrintWriter out, int[] array) {
        outArray(out, array, true);
    }

    public static void outArray(PrintWriter out, long[] array) {
        outArray(out, array, true);
    }

    public static void outArray(PrintWriter out, long[] array, boolean endLine) {
        boolean first = true;
        for (long x : array) {
            if (!first)
                out.print(' ');
            first = false;
            out.print(x);
        }
        if (endLine)
            out.println();
    }

    public static void outArray(PrintWriter out, int[] array, boolean endLine) {
        boolean first = true;
        for (int x : array) {
            if (!first)
                out.print(' ');
            first = false;
            out.print(x);
        }
        if (endLine)
            out.println();
    }

    public static void outArray(PrintWriter out, double[] array) {
        outArray(out, array, 6);
    }

    public static void outArray(PrintWriter out, double[] array, int precision) {
        outArray(out, array, precision, true);
    }


    public static void outArray(PrintWriter out, double[] array, int precision, boolean endLine) {
        String format = "%." + precision + "f";
        boolean first = true;
        for (double x : array) {
            if (!first)
                out.print(' ');
            first = false;
            out.printf(Locale.US, format, x);
        }
        if (endLine)
            out.println();
    }
}
